package webdev.utils;

import java.util.Calendar;

public class DateTimeUtil {

	/**This method will return the current date time follow format: dd/mm/yyyy hh/mm/ss
	 * @return Return date time follow this format dd/mm/yyyy hh/mm/ss
	 * @author thangtc
	 */
	public static String getCurrentDateTime() {
		Calendar cal = Calendar.getInstance();

		// get current day in month
		int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
		// get current month
		int month = cal.get(Calendar.MONTH) + 1;
		// get current year
		int year = cal.get(Calendar.YEAR);

		// get current hour 24h for a day
		int hour24 = cal.get(Calendar.HOUR);
		// get current minute
		int minute = cal.get(Calendar.MINUTE);
		// get current second
		int second = cal.get(Calendar.SECOND);

		String AM_PM;
		if (Calendar.AM == cal.get(Calendar.AM_PM)) {
			AM_PM = " AM";
		} else {
			AM_PM = " PM";
		}

		StringBuffer dateTimeString = new StringBuffer();
		dateTimeString.append(dayOfMonth);
		dateTimeString.append("/");
		dateTimeString.append(month);
		dateTimeString.append("/");
		dateTimeString.append(year);

		dateTimeString.append(" ");

		dateTimeString.append(hour24);
		dateTimeString.append(":");
		dateTimeString.append(minute);
		dateTimeString.append(":");
		dateTimeString.append(second);

		dateTimeString.append(AM_PM);

		return dateTimeString.toString();
    }
}
